package leetcode_900;

/**
 *@author 周杨
 *ConsecutiveNumbersSum_829 给定一个正整数N 问严格递增相加和为N的组合有多少
 *如9=9，5+4 ->2
 *describe:用数学方法
 *see:https://leetcode.com/problems/consecutive-numbers-sum/solution/
 *2018年10月30日 下午3:09:21
 */
public class ConsecutiveNumbersSum_829 {
	public int consecutiveNumbersSum(int N) {
		while ((N & 1) == 0) N >>= 1;
        int ans = 1, d = 3;
        while (d * d <= N) {
            int e = 0;
            while (N % d == 0) {
                N /= d;
                e++;
            }
            ans *= e + 1;
            d += 2;
        }
        if (N > 1) ans <<= 1;
        return ans;
    }
}
